//
//  XDShakeSearchCollectionViewCell.m
//  Le way walkers
//
//  Created by POP-mac on 15/5/23.
//  Copyright (c) 2015年 LTXZ. All rights reserved.
//

#import "XDShakeSearchCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@interface XDShakeSearchCollectionViewCell ()
@property (nonatomic, retain) UIImageView *photo;
@property (nonatomic, retain) UILabel *text;
@property (nonatomic, retain) UIView *back_view;
@end

@implementation XDShakeSearchCollectionViewCell

- (void)dealloc
{
    [self.text release];
    [self.photo release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.back_view = [[UIView alloc] init];
        [self.back_view setBackgroundColor:[UIColor whiteColor]];
        [self.contentView addSubview:self.back_view];
        
        self.text = [[[UILabel alloc] init] autorelease];
        [self.text setTextColor:[UIColor colorWithRed:50 / 255.0 green:179 / 255.0 blue:255 / 255.0 alpha:1]];
//        [self.text setBackgroundColor:[UIColor yellowColor]];
        [self.back_view addSubview:self.text];
        
        self.photo = [[[UIImageView alloc] init] autorelease];
        [self.photo setBackgroundColor:[UIColor greenColor]];
        [self.back_view addSubview:self.photo];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.back_view.frame = CGRectMake(15, 15, self.contentView.frame.size.width - 30, 90);
    self.text.frame = CGRectMake(100, 5, self.contentView.frame.size.width - 115 - 15, 20);
    self.photo.frame = CGRectMake(0, 0, 90, 90);
}

- (void)setShakeSearch:(XDShakeSearch *)shakeSearch
{
    if (_shakeSearch != shakeSearch) {
        [_shakeSearch release];
        _shakeSearch = [shakeSearch retain];
    }
    self.text.text = shakeSearch.name;
    [self.photo sd_setImageWithURL:[NSURL URLWithString:shakeSearch.cover_image] placeholderImage:[UIImage imageNamed:@"icon"]];
}

@end
